<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2024/9/18
  Time: 上午12:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>查看设备详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <!-- 设备编号 -->
    <div class="layui-form-item">
        <label class="layui-form-label">设备编号</label>
        <div class="layui-input-block">
            <input type="text" id="id" name="id" lay-verify="required" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 设备名称 -->
    <div class="layui-form-item">
        <label class="layui-form-label ">设备名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" lay-verify="required" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 设备类型 -->
    <div class="layui-form-item">
        <label class="layui-form-label ">设备类型</label>
        <div class="layui-input-block">
            <input type="text" id="type" name="type" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 所属学院 -->
    <div class="layui-form-item">
        <label class="layui-form-label ">所属学院</label>
        <div class="layui-input-block">
            <input type="text" id="college_id" name="college_id" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 所属教师 -->
    <div class="layui-form-item">
        <label class="layui-form-label ">所属教师</label>
        <div class="layui-input-block">
            <input type="text" id="staff_id" name="staff_id" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 借用权限 -->
    <div class="layui-form-item">
        <label class="layui-form-label ">借用权限</label>
        <div class="layui-input-block">
            <input type="text" id="is_available" name="is_available" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 设备状态 -->
    <div class="layui-form-item">
        <label class="layui-form-label">设备状态</label>
        <div class="layui-input-block">
            <input type="text" id="status" name="status" placeholder="" value="" class="layui-input" readonly>
        </div>
    </div>

    <!-- 备注信息 -->
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea id="remarks" name="remarks" class="layui-textarea" placeholder="" readonly></textarea>
        </div>
    </div>
</div>

<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form,
            $ = layui.jquery;

        // 获取设备ID
        var equipmentId = new URLSearchParams(window.location.search).get('id');

        if (equipmentId) {
            $.ajax({
                url: '${pageContext.request.contextPath}/equipmentServlet',
                type: 'GET',
                data: { method: 'getEquipmentById', id: equipmentId },
                success: function (response) {
                    var data = JSON.parse(response);
                    if (data.code === 0) {
                        var equipment = data.data;
                        // 填充表单
                        $('#id').val(equipment.id);
                        $('#name').val(equipment.name);
                        $('#type').val(equipment.type);
                        $('#college_id').val(equipment.college_id);
                        $('#staff_id').val(equipment.staff_id);
                        $('#is_available').val(equipment.is_available);
                        $('#status').val(equipment.status);
                        $('#remarks').val(equipment.remarks);
                    } else {
                        alert("设备详情获取失败");
                    }
                },
                error: function () {
                    alert("请求失败");
                }
            });
        } else {
            alert("未获取到设备ID");
        }
    });
</script>
</body>
</html>